// pages/diagnosis/diagnosis.js
var check = require('../../../utils/check.js');

var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    channel: [],
    theme: "常见并发症",
    cellList:[
      {
        index: 0,
        title: "静脉炎"
      },
      {
        index: 1,
        title: "皮肤过敏"
      },
      {
        index: 2,
        title: "穿刺点出血"
      },
      {
        index: 3,
        title: "导管堵塞"
      },
      {
        index: 4,
        title: "导管脱出"
      },
      {
        index: 5,
        title: "导管感染"
      },
      {
        index: 6,
        title: "血栓"
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      noPermitChannel: [
        {
          id: 0,
          enable: false,
          type: 'bindtap',
          iconUrl: "/static/patient/images/liuyan.png",
          name: "留言",
          url: "/pages/common/chat-window/chat-window?local=" + app.globalData.patientId + "&peer=" + app.globalData.nurseId
        },
        {
          id: 1,
          enable: true,
          type: 'bindtap',
          iconUrl: "/static/patient/images/phone.png",
          name: "电话",
        },
        {
          id: 2,
          enable: false,
          type: 'bindtap',
          iconUrl: "/static/patient/images/message.png",
          name: "短信",
          url: 'sms:18768116704&body=短信内容'
        },
        {
          id: 3,
          enable: false,
          type: 'bindtap',
          iconUrl: "/static/patient/images/weixin.png",
          name: "微信",
          url: "/pages/common/chat-window/chat-window?local=" + app.globalData.metaId + "&peer=" + app.globalData.myNurseId
        },
        {
          id: 4,
          enable: true,
          type: 'bindtap',
          iconUrl: "/static/patient/images/online.png",
          name: "在线咨询",
          url: "/pages/common/chat-window/chat-window?local=" + app.globalData.metaId + "&peer=" + app.globalData.myNurseId
        },
        {
          id: 5,
          enable: false,
          type: 'bindtap',
          iconUrl: "/static/patient/images/records.png",
          name: "记录",
          url: "/pages/common/chat-window/chat-window?local=" + app.globalData.metaId + "&peer=" + app.globalData.myNurseId
        }
      ],
      
      permitChannel: [
        {
          id: 0,
          enable: false,
          type: 'page',
          iconUrl: "/static/patient/images/liuyan.png",
          name: "留言",
          url: "/pages/common/chat-window/chat-window?local=" + app.globalData.patientId + "&peer=" + app.globalData.nurseId
        },
        {
          id: 1,
          enable: true,
          type: 'bindtap',
          iconUrl: "/static/patient/images/phone.png",
          name: "电话",
        },
        {
          id: 2,
          enable: false,
          type: 'page',
          iconUrl: "/static/patient/images/message.png",
          name: "短信",
          url: 'sms:18768116704&body=短信内容'
        },
        {
          id: 3,
          enable: false,
          type: 'page',
          iconUrl: "/static/patient/images/weixin.png",
          name: "微信",
          url: "/pages/common/chat-window/chat-window?local=" + app.globalData.metaId + "&peer=" + app.globalData.myNurseId
        },
        {
          id: 4,
          enable: true,
          type: 'page',
          iconUrl: "/static/patient/images/online.png",
          name: "在线咨询",
          url: "/pages/common/chat-window/chat-window?local=" + app.globalData.metaId + "&peer=" + app.globalData.myNurseId
        },
        {
          id: 5,
          enable: false,
          type: 'page',
          iconUrl: "/static/patient/images/records.png",
          name: "记录",
          url: "/pages/common/chat-window/chat-window?local=" + app.globalData.metaId + "&peer=" + app.globalData.myNurseId
        }
      ]
    });
    this.getIndexData();
    this.getScrollHeight();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  getIndexData: function () {
    let that = this;
    check.checkPermit().then(function(res){
      if(res){
        that.setData({
          channel: that.data.permitChannel
        });
      }else{
        that.setData({
          channel: that.data.noPermitChannel
        });
      }
    });
  },

  getScrollHeight: function(){
    let that = this;
    let windowHeight = 0;
    let screenHeight = 0;
    wx.getSystemInfo({
      success: function(res) {
        windowHeight = res.windowHeight;
        screenHeight = res.screenHeight;
        console.log("windowHeight = " + windowHeight);
        console.log("screenHeight = " + screenHeight);
        let componentWrap = wx.createSelectorQuery();
        componentWrap.select('#menu').boundingClientRect();
        componentWrap.select('#complication').boundingClientRect();
        let menuHeight = 0;
        let complicationHeight = 0;
        componentWrap.exec(function (res) {
          console.log("menu height = " + res[0].height);
          console.log("complication height = " + res[1].height);
          menuHeight = res[0].height;
          complicationHeight = res[1].height;
          var temp = windowHeight - menuHeight - complicationHeight;
          console.log("scroll height = " + temp );
          that.setData({
            scrollHeight: temp
          });
        });
      }
    });
  },

  btClick: function(event){
    let that = this;
    let id = event.currentTarget.dataset.id;
    console.log("btClick: " + id);
    check.checkPermit().then(function(res){
      if(res){
        that.setData({
          channel: that.data.permitChannel
        });
      }else{
        wx.showModal({
          title: '未审核，请耐心等待...'
        });
        return;
      }
      if(id == 1){
        wx.makePhoneCall({
          phoneNumber: app.globalData.nursePhone
        });
      }
    });
  },
  "disableScroll": true
})